import {
  defineStore
} from 'pinia'
import {
  ref
} from 'vue'

export const useLoginStore = defineStore('loginStore', () => {
  const token = ref('')
  const isLogin = ref(false)
  const loginUserInfo = ref({})
  token.value = ''
  isLogin.value = !! token.value
  loginUserInfo.value = {}
  const login = (tokenVal) => {
    token.value = tokenVal
    isLogin.value = !!tokenVal
  }
  const profile = (userInfoVal) => {
    loginUserInfo.value = userInfoVal
  }

  const logout = () => {
    token.value = ''
  }
  const getUserInfo = () => {
    return loginUserInfo.value
  }

  return {
    token,
    isLogin,
    loginUserInfo,
    login,
    logout,
    profile,
    getUserInfo
  }
})
